package cn.zbh._05_tran;

import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.client.producer.TransactionMQProducer;
import org.apache.rocketmq.client.producer.TransactionSendResult;
import org.apache.rocketmq.common.message.Message;

import java.nio.charset.StandardCharsets;

public class Producer {
    public static void main(String[] args) throws Exception {
        //事务
        TransactionMQProducer producer = new TransactionMQProducer("tran_a");

        producer.setNamesrvAddr("localhost:9876");

        producer.setTransactionListener(new MyTranListener());
        producer.start();
        Message message = new Message("tran-a", "hello", "好好学Java".getBytes(StandardCharsets.UTF_8));
        //发送事务信息
        TransactionSendResult result = producer.sendMessageInTransaction(message,null);
        System.out.println(result);

        producer.shutdown();

    }
}
